package com.ruoyi.training.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.training.mapper.KnowledgeBaseBooksMapper;
import com.ruoyi.training.domain.KnowledgeBaseBooks;
import com.ruoyi.training.service.IKnowledgeBaseBooksService;

/**
 * 知识库书籍Service业务层处理
 *
 * @author rocc
 * @date 2025-06-27
 */
@Service
public class KnowledgeBaseBooksServiceImpl implements IKnowledgeBaseBooksService {
    @Autowired
    private KnowledgeBaseBooksMapper knowledgeBaseBooksMapper;

    /**
     * 查询知识库书籍
     *
     * @param id 知识库书籍主键
     * @return 知识库书籍
     */
    @Override
    public KnowledgeBaseBooks selectKnowledgeBaseBooksById(Long id) {
        return knowledgeBaseBooksMapper.selectKnowledgeBaseBooksById(id);
    }

    /**
     * 查询知识库书籍列表
     *
     * @param knowledgeBaseBooks 知识库书籍
     * @return 知识库书籍
     */
    @Override
    public List<KnowledgeBaseBooks> selectKnowledgeBaseBooksList(KnowledgeBaseBooks knowledgeBaseBooks) {
        return knowledgeBaseBooksMapper.selectKnowledgeBaseBooksList(knowledgeBaseBooks);
    }

    /**
     * 新增知识库书籍
     *
     * @param knowledgeBaseBooks 知识库书籍
     * @return 结果
     */
    @Override
    public int insertKnowledgeBaseBooks(KnowledgeBaseBooks knowledgeBaseBooks) {
        Long userId = SecurityUtils.getUserId();
        knowledgeBaseBooks.setCreateBy(userId.toString());
        knowledgeBaseBooks.setCreateTime(DateUtils.getNowDate());
        return knowledgeBaseBooksMapper.insertKnowledgeBaseBooks(knowledgeBaseBooks);
    }

    /**
     * 修改知识库书籍
     *
     * @param knowledgeBaseBooks 知识库书籍
     * @return 结果
     */
    @Override
    public int updateKnowledgeBaseBooks(KnowledgeBaseBooks knowledgeBaseBooks) {
        Long userId = SecurityUtils.getUserId();
        knowledgeBaseBooks.setUpdateBy(userId.toString());
        knowledgeBaseBooks.setUpdateTime(DateUtils.getNowDate());
        return knowledgeBaseBooksMapper.updateKnowledgeBaseBooks(knowledgeBaseBooks);
    }

    /**
     * 批量删除知识库书籍
     *
     * @param ids 需要删除的知识库书籍主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeBaseBooksByIds(Long[] ids) {
        return knowledgeBaseBooksMapper.deleteKnowledgeBaseBooksByIds(ids);
    }

    /**
     * 删除知识库书籍信息
     *
     * @param id 知识库书籍主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeBaseBooksById(Long id) {
        return knowledgeBaseBooksMapper.deleteKnowledgeBaseBooksById(id);
    }
}
